<template>
  <!-- 登录 -->
  <div style="width:500px;">
    <el-form
      :model="typeDate"
      :rules="rules"
      ref="loginForm"
      label-width="60px"
    >
      <el-form-item label="类型" prop="name">
        <el-input v-model="typeDate.name" placeholder="请输入类型"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm('loginForm')"
          >创 建</el-button
        >
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import { createType } from "../../api/type";
export default {
  name: "typeCreate",
  components: {},
  data() {
    return {
      typeDate: {
        name: "",
      },
      rules: {
        name: [
          {
            required: true,
            message: "类型不能为空",
            trigger: "blur",
          },
        ],
      },
    };
  },
  methods: {
    // 提交登录
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          createType(this.typeDate).then((res) => {
            this.typeDate.name = "";
            this.$message({
              message: "添加成功",
              type: "success",
            });
          });
          // 发送请求
        } else {
          return false;
        }
      });
    },
  },
};
</script>
<style scoped></style>
